<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%-- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> --%>
<script type="text/javascript">
	$(function(){		
		function getItems(market){
			$('#categoryItems').empty();
			$('#categoryItems').append('<option value="all" label="ALL"/>');
			$.getJSON('<%= request.getContextPath()%>/setCategories.do',	//url 호출
			{								//데이터 전달
				market:market
			},function(data){				//서버응답시 실행할 function
				$(data).each(function(index, item){					
					var output = '';
					output += '<option value="'+item.c_code+'">'+item.category+'</option>';
					$('#categoryItems').append(output);					
				});
			});
		}
		
		$('#marketType').change(function(){
			getItems($('#marketType').val());
		});		
	});
</script>
<div class="manageList">
	<form action="productList.do" name="selector" method="get">
		<table class="selector">
			<tr>
				<td>
					<select name="searchMarket" id="marketType">					
						<option value="all">ALL</option>
						<option value="outer">OUTER</option>
						<option value="top">TOP</option>
						<option value="bottom">BOTTOM</option>
						<option value="dress">DRESS</option>
						<option value="shoes">SHOES</option>
						<option value="accessary">ACCESSARY</option>
					</select>
					<select name="searchCategory" id="categoryItems">
							<option value="all" label="ALL"/>
						<c:forEach	var="i" items="${categoryItem}">
							<option value="${i.c_code}" label="${i.category}"/>
						</c:forEach>					
					</select>
					<input type="submit" value="조회">
					<input type="button" value="등록" onclick="location.href='productWrite.do?pageNum=${pageNum}&	searchMarket=${searchMarket}&searchCategory=${searchCategory}'">
				</td>
			</tr>
		</table>
	</form>
	<table class="list">		
		<tr>
			<th>번호</th>
			<th>카테고리</th>
			<th>대분류</th>
			<th>상품명</th>
			<th>등록일</th>
			<th>전시여부</th>
			<th>편집</th>
		</tr>
		<c:forEach var="article" items="${list}">
		<tr>
			<td>${number} <c:set var="number" value="${number-1}" /></td>
			<td>${article.market}</td>
			<td>${article.category}</td>
			<td>${article.product}</td>
			<td>${article.regidate}</td>
			<td>${article.show}</td>
			<td>
				<c:if test="${article.show == 'n'}">
					<input type="button" value="공개" onclick="location.href='productShowToggle.do?p_code=${article.p_code}&pageNum=${pageNum}&searchMarket=${searchMarket}&searchCategory=${searchCategory}'">
				</c:if>
				<c:if test="${article.show == 'y'}">
					<input type="button" value="비공개" onclick="location.href='productShowToggle.do?p_code=${article.p_code}&pageNum=${pageNum}&searchMarket=${searchMarket}&searchCategory=${searchCategory}'">
				</c:if>
				<input type="button" value="상세" onclick="location.href='productDetail.do?p_code=${article.p_code}&c_code=${article.c_code}&pageNum=${pageNum}&	searchMarket=${searchMarket}&searchCategory=${searchCategory}'">
				<input type="button" value="수정" onclick="location.href='productUpdate.do?p_code=${article.p_code}&c_code=${article.c_code}&pageNum=${pageNum}&	searchMarket=${searchMarket}&searchCategory=${searchCategory}'">				
				<input type="button" value="삭제" onclick="location.href='productDelete.do?p_code=${article.p_code}&c_code=${article.c_code}&pageNum=${pageNum}&	searchMarket=${searchMarket}&searchCategory=${searchCategory}'">				
			</td>
		</tr>
		</c:forEach>
		<c:if test="${count == 0}">
		<tr>
			<td colspan="5">표시할 내용이 없습니다.</td>
		</tr>
		</c:if>
	</table>
	<table class="page">
		<c:if test="${count>0}">
		<tr>
			<td>${pagingHtml}</td>
		</tr>
		</c:if>
	</table>
</div>